/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * ***************************************************************************/


#include "stdafx.h"

#ifdef _DLL

#include <afxdllx.h>
#include <pgl/core/PGLColor.h>

#ifdef _PGL_SHAREWARE
	#include "Expire.h"
#endif


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


static AFX_EXTENSION_MODULE PGLCoreDLL = { NULL, NULL };

extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
	// Remove this if you use lpReserved
	UNREFERENCED_PARAMETER(lpReserved);

	if (dwReason == DLL_PROCESS_ATTACH)
	{
		PGL_TRACE(_T("Plot Graphic Library Kernel Initializing!\n"));
		
		// Extension DLL one-time initialization
		if (!AfxInitExtensionModule(PGLCoreDLL, hInstance))
			return 0;

		new CDynLinkLibrary(PGLCoreDLL);

		CPGLColor::PrepareClassicColors();
		PGL_TRACE(_T("Plot Graphic Library Kernel Initiallized\n"));
	}
	else if (dwReason == DLL_PROCESS_DETACH)
	{
		PGL_TRACE(_T("Plot Graphic Library Kernel Terminating!\n"));

		// Terminate the library before destructors are called
		singletons::CDestroyObjects destroyObjects;

		AfxTermExtensionModule(PGLCoreDLL);
	}
	return 1;   // ok
}

#endif
